import { defineAmisPlugin, getApiTpl, getApiTpls, getInputTpl } from '../../base/util';
import ListPage from './fc';
import type { IProps } from './interface';
import { LIST_TREE_TYPE } from '@/pages/editor/lowcode/data';

export default defineAmisPlugin<IProps>(({ amisEditor }) => {
  const { getSchemaTpl } = amisEditor;
  return {
    component: ListPage,
    options: {
      type: 'list-page',
      name: '列表模板',
      order: -9999,
      disabledRendererPlugin: true,
      icon: 'fa fa-tree',
      description: '列表模板，包含项目组织树、内嵌查询及列表的组件集',
      tags: ['页面模板'],
      scaffold: {
        showProjectOrgTree: true,
        orgTreeType: LIST_TREE_TYPE.PROJECT,
        toolbar: {
          type: 'tool-bar',
          buttonSize: 'middle',
          buttonType: 'primary',
          buttons: [
            { itemId: 'add', text: '新增', icon: 'FileAddOutlined' },
            { itemId: 'edit', text: '修改', icon: 'EditOutlined' },
            { itemId: 'delete', text: '删除', icon: 'DeleteOutlined' }],
        },
        table: {
          type: 'table',
          columns: [],
        },
      },
      //区域的内容需要是数组，否则会被amis渲染一次后转换成数组
      regions: [
        {
          key: 'toolbar',
          label: '列表模板-工具条区域',
        },
        {
          key: 'table',
          label: '列表模板-列表区域',
        },
      ],
      panelBodyCreator(context: any) {
        return getSchemaTpl('tabs', getSchemaTpl('commonTpl', {
          scope: this,
          context,
          groups: [
            {
              title: '基本属性',
              body: [
                getInputTpl('busType', { label: "业务类型" , readOnly: true, required: true,}),
                getInputTpl('showProjectOrgTree', { type: "switch", label: "左侧树" }),
                getInputTpl('orgTreeType', { type: 'select', label: '树类型', 
                    options: [
                      { label: '项目管理组织树', value: LIST_TREE_TYPE.PROJECT }, 
                      { label: '组织树', value: LIST_TREE_TYPE.ORG },
                      { label: '组织部门树', value: LIST_TREE_TYPE.DEPT }
                    ]
                }),
              ],
            },
            getApiTpls('数据源', [
              {
                name: 'requestList',
                label: '获取列表数据',
                data: {
                  code: 0,
                  data: {
                    list: [],
                    pageNum: 1,
                    pageSize: 15,
                    total: 0,
                  },
                  message: '',
                },
              },
              {
                name: 'requestDelete',
                label: '删除',
                data: {
                  code: 0,
                  data: true,
                  message: '',
                },
              },
            ]),
          ],
        }));
      },
    },
  };
});
